# 猜数字
import random

print("猜数字游戏开始，共5次机会哟")
while True:
    result = random.randint(0, 30)
    flag = False
    score = 100
    for i in range(1, 6):
        guess = ''
        while True:
            guess = input("请输入0至30的数字：")
            if guess.isdigit():
                break
            else:
                print("输入数字，别输错了，请再输入")
        guess = int(guess)
        if guess == result:
            flag = True
            print("恭喜您，猜对了，答案是{} 得分为 {}".format(result, score))
            break
        elif guess > result:
            score -= 20
            print("您猜的高了")
        else:
            score -= 20
            print("您猜的低了")
    if flag:
        pass
    else:
        print("五次机会已用完，猜数字失败，正确答案是 {} 得分为 {}".format(result, score))
